﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Xml.Serialization;
using CafeOnline.MvcFramework.Web;

namespace CafeOnline.MvcFramework.Grid {
    [ModelBinder(typeof(GridModelBinder))]
    public class GridSettings {
        public bool IsSearch {
            get;
            set;
        }
        public int PageSize {
            get;
            set;
        }
        public int PageIndex {
            get;
            set;
        }
        public string SortColumn {
            get;
            set;
        }
        public string SortOrder {
            get;
            set;
        }
        public Filter Where {
            get;
            set;
        }
    }
    [Serializable]
    public class GridCustomSettings {
        #region IProperties

        public List<ColumnCustomSettings> Columns {
            get;
            set;
        }

        #endregion IProperties
        #region IConstructors

        public GridCustomSettings() {
            Columns = new List<ColumnCustomSettings>();
        }

        #endregion IConstructors
    }
    public class ColumnCustomSettings {
        #region IProperties

        [XmlAttribute]
        public string Name {
            get;
            set;
        }

        public int? Width {
            get;
            set;
        }

        public bool Visible {
            get;
            set;
        }
        public int Order {
            get;
            set;
        }

        #endregion IProperties
        #region IMethods

        public override bool Equals(object obj) {
            ColumnCustomSettings ccs = obj as ColumnCustomSettings;
            if (ccs != null) {
                return ccs.Name.Equals(Name);
            }
            return false;
        }

        public override int GetHashCode() {
            return Name.GetHashCode();
        }

        #endregion IMethods
    }
}
